#include "StdAfx.h"
#include "Lock.h"

CLock::CLock(void)
{
	InitializeCriticalSection(&m_sectioon);
}

CLock::~CLock(void)
{
	DeleteCriticalSection(&m_sectioon);
}

void CLock::Lock()
{
	EnterCriticalSection(&m_sectioon);
}

void CLock::UnLock()
{
	LeaveCriticalSection(&m_sectioon);
}


CAutoLock::CAutoLock(CLock& lock)
{
	m_lock = &lock;
	lock.Lock();
}

CAutoLock::~CAutoLock(void)
{
	if (m_lock != NULL)
		m_lock->UnLock();
}
